package com.firestone.service.center.impl;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.firestone.bean.dto.terminal.TerminalDTO;
import com.firestone.bean.entity.mysql.primary.ImCenterTerminalMenu;
import com.firestone.dao.primary.center.ImCenterTerminalMenuDao;
import com.firestone.service.center.IImCenterTerminalMenuService;

/**
 * <p>
 * 具体分支系统菜单 服务实现类
 * </p>
 *
 * @author CAIYJ
 * @since 2018-03-27
 */
@Service
public class ImCenterTerminalMenuServiceImpl
        extends ServiceImpl<ImCenterTerminalMenuDao, ImCenterTerminalMenu>
        implements IImCenterTerminalMenuService {

    @Override
    public Page<TerminalDTO> listTerminal(Page<TerminalDTO> page,
            String name) throws Exception {
        EntityWrapper<TerminalDTO> ew = new EntityWrapper<TerminalDTO>();
        ew.setEntity(new TerminalDTO());
        ew.where(StringUtils.isNotBlank(name),
                "ctm.`name` LIKE concat('%',{0},'%')", name);
        String[] columns = {"ctm.update_time"};
        ew.orderDesc(Arrays.asList(columns));
        List<TerminalDTO> list = this.baseMapper.selectTerminalList(page, ew);
        return page.setRecords(list);
    }

}
